package com.insyte.utils;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 23/01/2015.
 */
public class Initialize {
    public ProgressDialog progressDialog;
    public Context context;
    public Map<String, Object> params;

    public Initialize(Context context) {
        this.context = context;
    }

    public Map<String, Object> createParams() {
        SharedPreferences userInfo = context.getSharedPreferences("dataUserInfo", context.MODE_PRIVATE);
        params = new HashMap<String, Object>();
        params.put("user_id", userInfo.getString("user_id", ""));
        params.put("token", userInfo.getString("token", ""));
        params.put("device_id", userInfo.getString("device_id", ""));

        return params;
    }

    public ProgressDialog createProgressDialog(String message) {
        progressDialog = new ProgressDialog(context);
        progressDialog.setMessage(message + "...");
        progressDialog.setCanceledOnTouchOutside(false);

        return progressDialog;
    }

    public void showToast(String message) {
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }

    public boolean checkNetwork() {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

        return networkInfo != null && networkInfo.isConnectedOrConnecting();
    }
}
